"""get_weather URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
import logging,os

from django.conf.urls import url
from django.urls import path
from API_getWeather.views import allViews
from templates.dataMysql import querySave, deleteDatas
from apscheduler.scheduler import Scheduler

urlpatterns = [
    # url('', allViews().index),
    path('', allViews().search_code, name='check'), # 查询城市名称
    path('todayWeather/', allViews().get_todayWeather, name='todayWeather'),  # 今天天气
    path('timesForecast/', allViews().get_timesForecast, name='timesForecast'),  # 最近7天
    path('hourlyWeather/', allViews().get_houlryWeather, name='hourlyWeather'),  # 整点天气
]




logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s',
)
def kill():
    os.system('taskkill /F /im chrome.exe ')  # 杀进程
    os.system('taskkill /F /im chromedriver.exe ')

# ===============定时爬取今日数据==============
# 请求必须在每小时6分过后
sched = Scheduler()  # 实例化对象
# 设置1小时爬取一次today数据
sched.add_cron_job(func=querySave().saveByToday, hour='*', minute='02')  # 每小时1分执行
sched.add_cron_job(func=querySave().savaByHours, hour='*', minute='11')
sched.add_cron_job(func=deleteDatas().delByHours, hour='01', minute='00')
sched.add_cron_job(func=deleteDatas().delByToday, hour='01', minute='00')
sched.add_cron_job(func=kill, hour='00', minute='00')   # 每天晚上0点,执行杀谷歌浏览进程
sched.start()  # 启动
logging.info(sched)
